home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!pipeline!not-for-mail
- From: johndill@nyc.pipeline.com (John Dillworth)
- Newsgroups: comp.lang.c
- Subject: Keep SetPixel in center
- Date: 29 Feb 1996 07:07:16 -0500
- Organization: The Pipeline
- Message-ID: <4h44tk$i24@pipe12.nyc.pipeline.com>
- NNTP-Posting-Host: pipe12.nyc.pipeline.com
- X-PipeUser: johndill
- X-PipeHub: nyc.pipeline.com
- X-PipeGCOS: (John Dillworth)
- X-Newsreader: The Pipeline v3.4.0
-
- I have the following program. I want to turn one pixel on and have it stay
- in the center of the screen when ever I resize it. I have managed to get
- the pixel on the screen. How can I keep it in the canter??
-
- #include <windows.h>
-
-
- long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
-
- int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdParam, int nCmdShow)
- {
- static char szAppName[] = "HelloWin" ;
- HWND hwnd ;
- MSG msg ;
- WNDCLASS wndclass ;
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW ;
- wndclass.lpfnWndProc = WndProc ;
- wndclass.cbClsExtra = 0 ;
- wndclass.cbWndExtra = 0 ;
- wndclass.hInstance = hInstance ;
- wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
- wndclass.hbrBackground = GetStockObject (BLACK_BRUSH) ;
- wndclass.lpszMenuName = NULL ;
- wndclass.lpszClassName = szAppName ;
-
- RegisterClass (&wndclass) ;
- }
-
- hwnd = CreateWindow (szAppName, // window class name
- "The Hello Program", // window caption
- WS_OVERLAPPEDWINDOW, // window style
- CW_USEDEFAULT, // initial x position
- CW_USEDEFAULT, // initial y position
- CW_USEDEFAULT, // initial x size
- CW_USEDEFAULT, // initial y size
- NULL, // parent window handle
- NULL, // window menu handle
- hInstance, // program instance handle
- NULL) ; // creation parameters
-
- ShowWindow (hwnd, nCmdShow) ;
- UpdateWindow (hwnd) ;
-
- while (GetMessage (&msg, NULL, 0, 0))
- {
- TranslateMessage (&msg) ;
- DispatchMessage (&msg) ;
- }
- return msg.wParam ;
- }
-
- long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam,
- LONG lParam)
- {
- HDC hdc ;
- PAINTSTRUCT ps ;
- RECT rect ;
-
- switch (message)
- {
- case WM_PAINT:
- hdc = BeginPaint (hwnd, &ps) ;
-
- GetClientRect (hwnd, &rect) ;
-
- // DrawText (hdc, "Hello, Windows!", -1, &rect,
- // DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
- SetPixel (hdc, 40,150, RGB(150, 0, 0));
- EndPaint (hwnd, &ps) ;
-
- return 0 ;
-
- case WM_DESTROY:
- PostQuitMessage (0) ;
- return 0 ;
- }
-
- return DefWindowProc (hwnd, message, wParam, lParam) ;
- }
-